---
title: "Analysis: Intervention Asymmetry"
output: html_document
---

```{r}

# set r markdown chunk defaults
knitr::opts_chunk$set(warning = F, message = F)

```

# Description

The code below imports the cleaned YouGov data (created in 'cleaning.Rmd') and runs the analysis used to create Figures 5 and 6 in the manuscript. 

# Setup

```{r}

# clearing memory --------------------------------------------------------------
rm(list = ls())

start_time <- Sys.time()


# load packages ----------------------------------------------------------------
library(here)
library(tidyverse)
library(survey)
library(srvyr)
library(ggeffects)
library(stargazer)
library(broom)
library(ggstance)
library(ggpubr)
library(arm)
library(gridExtra)
library(doParallel)
library(foreach)
library(broom)
library(margins)
library(patchwork)
library(relimp, pos = 4)
library(paran)
library(clarify)
library(viridis)
library(stringr)

# useful functions -------------------------------------------------------------

# function to calculate standard error of mean
std_error <- function(var){
  sd(var, na.rm = T) / sqrt(length(var[!is.na(var)]))
}

# function to manually bin continous variables
bin_fun <- function(x, bin_size){
  bin_size * ceiling(x / bin_size) - bin_size / 2
}

# function to put variables on a 0-1 scale
rescale_01 <- function(x, max){
  (x-1)/(max-1)
}

# function to compute two-way clustered standard errors with survey weights
source(here("code", "helper functions", "glmweave.R"))


# set n_sim
n_sim <- 1000

# set seed
set.seed(4787)

# plotting colors
cb_black <- "#000000" # Discernment / all headlines
cb_blue <- "#0072B2"  # Democratic headlines
cb_red<- "#D55E00"    # Republican headlines
cb_green = "#009E73"  # True headlines
cb_orange = "#E69F00" # False headlines

```

```{r}

# load cleaned data
long <- read.csv(here("data", "cleaned", "long.csv"))
yougov <- read.csv(here("data", "cleaned", "yougov.csv"))

```


# Main Experimental Analysis Without Controls 

The three chunks of code below follow the same structure. First, a dataset is created for the subset of models run in the chunk. Second, models are run on 1) all headlines, 2) true headlines, and 3) false headlines. Third, simulation-based inference is used to calculate quantities of interest (e.g., multiplicative and additive discernment).

Guide to model nomenclature: 

all headlines: 
- m5: run three-way interaction. Finding: No significant multiplicative or additive difference
- m6: run two-way interaction, for Republicans only
- m7: run two-way interaction, for Democrats only

agreeable headlines: 
- m8: run three-way interaction. Finding: No significant multiplicative or additive difference
- m9: run two-way interaction, for Republicans only
- m10: run two-way interaction, for Democrats only

disagreeable headlines: 
- m11: run three-way interaction. Finding: No significant multiplicative or additive difference
- m12: run two-way interaction, for Republicans only
- m13: run two-way interaction, for Democrats only

other:
- m14: run four-way interaction w agreeableness 


## All Headlines, All Respondents, Three-Way Interaction (Veracity X PooledTreat X Party)

```{r}

m5nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data)

m5nc_true <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data %>% filter(hdl_true == 1))

m5nc_false <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data %>% filter(hdl_true == 0))

m5nc_sim <- 
  clarify::sim(m5nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_all, g1 = m5nc_all$data$caseid, g2 = m5nc_all$data$hdl_id))

m5nc_sim_apply <- 
  sim_apply(m5nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_transformed <-
  transform(m5nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


## All Headlines, Republican Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m6nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data)

m6nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data %>% filter(hdl_true == 1))

m6nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data %>% filter(hdl_true == 0))

m6nc_sim <- 
  clarify::sim(m6nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_all, g1 = m6nc_all$data$caseid, g2 = m6nc_all$data$hdl_id))

m6nc_sim_apply <- 
  sim_apply(m6nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_transformed <-
  transform(m6nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

## All Headlines, Democratic Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m7nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()

m7nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data)

m7nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data %>% filter(hdl_true == 1))

m7nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data %>% filter(hdl_true == 0))

m7nc_sim <- 
  clarify::sim(m7nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_all, g1 = m7nc_all$data$caseid, g2 = m7nc_all$data$hdl_id))

m7nc_sim_apply <- 
  sim_apply(m7nc_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_transformed <-
  transform(m7nc_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```

# Main Experimental Analysis With Controls 

The three chunks of code below follow the same structure. First, a dataset is created for the subset of models run in the chunk. Second, models are run on 1) all headlines, 2) true headlines, and 3) false headlines. Third, simulation-based inference is used to calculate quantities of interest (e.g., multiplicative and additive discernment).

The models use the same style of naming convention described above.

## All Headlines, All Respondents, Three-Way Interaction (Veracity X PooledTreat X Party)

```{r}

m5c_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, age_sd, female, education_sd, pooledTreat, weight, caseid, hdl_id) %>%
  na.omit()

m5c_all <-  
  glm(share_01 ~ 
        hdl_true*pooledTreat*party_dem + 
        hdl_true*pooledTreat*age_sd + 
        hdl_true*pooledTreat*female + 
        hdl_true*pooledTreat*education_sd,
      family = "gaussian", weights = weight, data = m5c_data)

m5c_true <-  
  glm(share_01 ~ 
        pooledTreat*party_dem + 
        pooledTreat*age_sd + 
        pooledTreat*female + 
        pooledTreat*education_sd,
      family = "gaussian", weights = weight, data = m5c_data %>% filter(hdl_true == 1))

m5c_false <-  
  glm(share_01 ~ 
        pooledTreat*party_dem + 
        pooledTreat*age_sd + 
        pooledTreat*female + 
        pooledTreat*education_sd,
      family = "gaussian", weights = weight, data = m5c_data %>% filter(hdl_true == 0))

m5c_sim <- 
  clarify::sim(m5c_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5c_all, g1 = m5c_all$data$caseid, g2 = m5c_all$data$hdl_id))

m5c_sim_apply <- 
  sim_apply(m5c_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5c_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5c_transformed <-
  transform(m5c_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


## All Headlines, Republican Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m6c_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, age_sd, female, education_sd, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6c_all <-  
  glm(share_01 ~ hdl_true*pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m6c_data)

m6c_true <-  
  glm(share_01 ~ pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m6c_data %>% filter(hdl_true == 1))

m6c_false <-  
  glm(share_01 ~ pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m6c_data %>% filter(hdl_true == 0))

m6c_sim <- 
  clarify::sim(m6c_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6c_all, g1 = m6c_all$data$caseid, g2 = m6c_all$data$hdl_id))

m6c_sim_apply <- 
  sim_apply(m6c_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6c_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6c_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6c_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6c_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6c_transformed <-
  transform(m6c_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

## All Headlines, Democratic Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m7c_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, age_sd, female, education_sd, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7c_all <-  
  glm(share_01 ~ hdl_true*pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m7c_data)

m7c_true <-  
  glm(share_01 ~ pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m7c_data %>% filter(hdl_true == 1))

m7c_false <-  
  glm(share_01 ~ pooledTreat + age_sd + female + education_sd,
      family = "gaussian", weights = weight, data = m7c_data %>% filter(hdl_true == 0))

m7c_sim <- 
  clarify::sim(m7c_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7c_all, g1 = m7c_all$data$caseid, g2 = m7c_all$data$hdl_id))

m7c_sim_apply <- 
  sim_apply(m7c_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7c_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7c_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7c_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7c_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7c_transformed <-
  transform(m7c_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```


# Supplementary Experimental Analysis Without Controls

The seven chunks of code below follow the same structure. First, a dataset is created for the subset of models run in the chunk. Second, models are run on 1) all headlines, 2) true headlines, and 3) false headlines. Third, simulation-based inference is used to calculate quantities of interest (e.g., multiplicative and additive discernment).

The models use the same style of naming convention described above.

## Agreeable Headlines, All Respondents, Three-Way Interaction (Veracity X PooledTreat X Party)

```{r}

m8nc_data <- 
  long %>% 
  filter(hdl_agreeable == 1) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  na.omit()

m8nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m8nc_data)

m8nc_true <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m8nc_data %>% filter(hdl_true == 1))

m8nc_false <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m8nc_data %>% filter(hdl_true == 0))

m8nc_sim <- 
  clarify::sim(m8nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m8nc_all, g1 = m8nc_all$data$caseid, g2 = m8nc_all$data$hdl_id))

m8nc_sim_apply <- 
  sim_apply(m8nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0), type = "response")
              true_left_control <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m8nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m8nc_transformed <-
  transform(m8nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


## Agreeable Headlines, Republican Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m9nc_data <- 
  long %>% 
  filter(hdl_agreeable == 1) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m9nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m9nc_data)

m9nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m9nc_data %>% filter(hdl_true == 1))

m9nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m9nc_data %>% filter(hdl_true == 0))

m9nc_sim <- 
  clarify::sim(m9nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m9nc_all, g1 = m9nc_all$data$caseid, g2 = m9nc_all$data$hdl_id))

m9nc_sim_apply <- 
  sim_apply(m9nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m9nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m9nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")

              true_right_control <- predict(fit, newdata = m9nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m9nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m9nc_transformed <-
  transform(m9nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

## Agreeable Headlines, Democratic Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m10nc_data <- 
  long %>% 
  filter(hdl_agreeable == 1) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m10nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m10nc_data)

m10nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m10nc_data %>% filter(hdl_true == 1))

m10nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m10nc_data %>% filter(hdl_true == 0))

m10nc_sim <- 
  clarify::sim(m10nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m10nc_all, g1 = m10nc_all$data$caseid, g2 = m10nc_all$data$hdl_id))

m10nc_sim_apply <- 
  sim_apply(m10nc_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m10nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m10nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m10nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m10nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m10nc_transformed <-
  transform(m10nc_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```


## Disagreeable Headlines, All Respondents, Three-Way Interaction (Veracity X PooledTreat X Party)

```{r}

m11nc_data <- 
  long %>% 
  filter(hdl_agreeable == 0) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  na.omit()

m11nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m11nc_data)

m11nc_true <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m11nc_data %>% filter(hdl_true == 1))

m11nc_false <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m11nc_data %>% filter(hdl_true == 0))

m11nc_sim <- 
  clarify::sim(m11nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m11nc_all, g1 = m11nc_all$data$caseid, g2 = m11nc_all$data$hdl_id))

m11nc_sim_apply <- 
  sim_apply(m11nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0), type = "response")
              true_left_control <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m11nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m11nc_transformed <-
  transform(m11nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


## Disagreeable Headlines, Republican Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m12nc_data <- 
  long %>% 
  filter(hdl_agreeable == 0) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m12nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m12nc_data)

m12nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m12nc_data %>% filter(hdl_true == 1))

m12nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m12nc_data %>% filter(hdl_true == 0))

m12nc_sim <- 
  clarify::sim(m12nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m12nc_all, g1 = m12nc_all$data$caseid, g2 = m12nc_all$data$hdl_id))

m12nc_sim_apply <- 
  sim_apply(m12nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m12nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m12nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")

              true_right_control <- predict(fit, newdata = m12nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m12nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m12nc_transformed <-
  transform(m12nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

## Disagreeable Headlines, Democratic Respondents, Two-Way Interaction (Veracity X PooledTreat)

```{r}

m13nc_data <- 
  long %>% 
  filter(hdl_agreeable == 0) %>%
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m13nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m13nc_data)

m13nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m13nc_data %>% filter(hdl_true == 1))

m13nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m13nc_data %>% filter(hdl_true == 0))

m13nc_sim <- 
  clarify::sim(m13nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m13nc_all, g1 = m13nc_all$data$caseid, g2 = m13nc_all$data$hdl_id))

m13nc_sim_apply <- 
  sim_apply(m13nc_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m13nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m13nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m13nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m13nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m13nc_transformed <-
  transform(m13nc_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```


## All Headlines, All Respondents, Four-Way Interaction (Veracity X PooledTreat X Party X Agreeable)

```{r}

m14nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, hdl_agreeable, weight, caseid, hdl_id) %>%
  na.omit()

m14nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat*party_dem*hdl_agreeable,
      family = "gaussian", weights = weight, data = m14nc_data)

m14nc_true <-  
  glm(share_01 ~ pooledTreat*party_dem*hdl_agreeable,
      family = "gaussian", weights = weight, data = m14nc_data %>% filter(hdl_true == 1))

m14nc_false <-  
  glm(share_01 ~ pooledTreat*party_dem*hdl_agreeable,
      family = "gaussian", weights = weight, data = m14nc_data %>% filter(hdl_true == 0))

m14nc_sim <- 
  clarify::sim(m14nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m14nc_all, g1 = m14nc_all$data$caseid, g2 = m14nc_all$data$hdl_id))

m14nc_sim_apply <- 
  sim_apply(m14nc_sim, cl = 6,
            function(fit){
              # agreeable
              true_right_treat_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1, hdl_agreeable = 1), type = "response")
              true_left_treat_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1, hdl_agreeable = 1), type = "response")
              false_right_treat_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1, hdl_agreeable = 1), type = "response")
              false_left_treat_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1, hdl_agreeable = 1), type = "response")
              
              true_right_control_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0, hdl_agreeable = 1), type = "response")
              true_left_control_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0, hdl_agreeable = 1), type = "response")
              false_right_control_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0, hdl_agreeable = 1), type = "response")
              false_left_control_agreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0, hdl_agreeable = 1), type = "response")
              
            
              # disagreeable
              true_right_treat_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1, hdl_agreeable = 0), type = "response")
              true_left_treat_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1, hdl_agreeable = 0), type = "response")
              false_right_treat_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1, hdl_agreeable = 0), type = "response")
              false_left_treat_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1, hdl_agreeable = 0), type = "response")
              
              true_right_control_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0, hdl_agreeable = 0), type = "response")
              true_left_control_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0, hdl_agreeable = 0), type = "response")
              false_right_control_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0, hdl_agreeable = 0), type = "response")
              false_left_control_disagreeable <- predict(fit, newdata = m14nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0, hdl_agreeable = 0), type = "response")
              
              c(
              c(true_right_treat_agreeable = mean(true_right_treat_agreeable), true_left_treat_agreeable = mean(true_left_treat_agreeable), 
                false_right_treat_agreeable = mean(false_right_treat_agreeable), false_left_treat_agreeable = mean(false_left_treat_agreeable), 
                true_right_control_agreeable = mean(true_right_control_agreeable), true_left_control_agreeable = mean(true_left_control_agreeable), 
                false_right_control_agreeable = mean(false_right_control_agreeable), false_left_control_agreeable = mean(false_left_control_agreeable)),
              
              c(true_right_treat_disagreeable = mean(true_right_treat_disagreeable), true_left_treat_disagreeable = mean(true_left_treat_disagreeable), 
                false_right_treat_disagreeable = mean(false_right_treat_disagreeable), false_left_treat_disagreeable = mean(false_left_treat_disagreeable), 
                true_right_control_disagreeable = mean(true_right_control_disagreeable), true_left_control_disagreeable = mean(true_left_control_disagreeable), 
                false_right_control_disagreeable = mean(false_right_control_disagreeable), false_left_control_disagreeable = mean(false_left_control_disagreeable)))
              })

# for the four-way, just save the QOI. Do separately for diff and ratio
m14nc_transformed <-
  transform(m14nc_sim_apply, 
            
               # agreeable
            `diff` = (((true_left_treat_agreeable - false_left_treat_agreeable) - (true_right_treat_agreeable - false_right_treat_agreeable)) - 
                     ((true_left_control_agreeable - false_left_control_agreeable) - (true_right_control_agreeable - false_right_control_agreeable))) - 
              # disagreeable
              (((true_left_treat_disagreeable - false_left_treat_disagreeable) - (true_right_treat_disagreeable - false_right_treat_disagreeable)) - 
                     ((true_left_control_disagreeable - false_left_control_disagreeable) - (true_right_control_disagreeable - false_right_control_disagreeable))), 
            
              # agreeable
            `ratio` = (((true_left_treat_agreeable / false_left_treat_agreeable) / (true_right_treat_agreeable / false_right_treat_agreeable)) / 
                     ((true_left_control_agreeable / false_left_control_agreeable) / (true_right_control_agreeable / false_right_control_agreeable))) / 
              # disagreeable
              (((true_left_treat_disagreeable / false_left_treat_disagreeable) / (true_right_treat_disagreeable / false_right_treat_disagreeable)) / 
                     ((true_left_control_disagreeable / false_left_control_disagreeable) / (true_right_control_disagreeable / false_right_control_disagreeable))))

```

# Figures

The subsections below are labeled with the figure they create and are further separated by the panel of each figure.

## Figure 5: Agreeable + Disagreeable Headlines Together, No Controls

### Top Row: Means

```{r}

fig5_nc <- 
  
svyby(~share_01, ~hdl_true + ~party_dem + ~pooledTreat, 
      FUN = svymean, 
      design = svydesign(~1, 
                         weights = ~weight, 
                         data = long %>% 
                           dplyr::select(share_01, hdl_true, hdl_agreeable, 
                                         party_dem, pooledTreat, 
                                         weight, caseid, hdl_id) %>%
                           na.omit())) %>%
  
  mutate(hdl_true = ifelse(hdl_true == 1, "True Headlines", "False Headlines")) %>%
  mutate(party_dem = ifelse(party_dem == 0, "Republicans", "Democrats")) %>%

  ggplot(aes(x = factor(party_dem), 
             y = share_01, 
             ymin = share_01 - 1.96*se, 
             ymax = share_01 + 1.96*se,
             label = round(share_01, 2),
             fill = factor(pooledTreat))) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(size = .3, width = .2, position = position_dodge(.9)) + 

  geom_text(aes(y = share_01 + 1.96*se), 
            position = position_dodge(.9), vjust = -1, size = 3) +  

  facet_wrap(vars(hdl_true)) + 
  #facet_grid(cols = vars(hdl_agreeable), rows = vars(hdl_true)) + 
  theme_minimal() + 
  # scale_fill_manual(breaks = c("Democrats", "Republicans"), 
  #                   labels = c("Democrats", "Republicans"), 
  #                   values = c(cb_blue, cb_red), 
  #                   name = "Respondent Party") + 
  xlab("Respondent Party") + 
  ylab("Mean Sharing Intention (0-1)") + 
  ylim(c(0, .5)) + 
  scale_fill_manual(breaks = c(0, 1), 
                    labels = c("Control", "Treatment"), 
                    values = c("gray80", "gray40"), 
                    name = "") + 
  theme(legend.position = c(.2, .9)) + 
  theme(strip.text.x = element_text(size = 12))

```

### Bottom Row: Discernment

```{r}

fig5_dem_rep <- 
  
  rbind(
    
    summary(m6nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans"),
    
    summary(m7nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats")) %>%
    
  
  ggplot(aes(x = respondent_party, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 1) +
  geom_pointrange(position = position_dodge(.4)) + 
  # scale_color_manual(breaks = c("Democratic", "Republican"), 
  #                    values = c(cb_blue, cb_red))   + 
  theme_bw() + 
  xlab("") + 
  ylim(c(.8, 1.35)) + 
  ylab("Treatment Effect on Discernment")

fig5_dem_vs_rep <- 
  rbind(
    
    summary(m5nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratioleft_div_ratioright") %>% 
      mutate(respondent_party = "All")) %>%
    
    mutate(quantity = ifelse(quantity == "ratioleft_div_ratioright", "Treatment Effect on Discernment: Democrat / Republican", NA)) %>%
  
  ggplot(aes(x = quantity, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 1) + 
  geom_pointrange(position = position_dodge(.4)) +
  theme(legend.position = "none") + 
  theme_bw() + 
  xlab("") + 
  ylab("Treatment Effect on Discernment \n(Democrat / Republican)") + 
  ylim(c(.8, 1.35)) 

```

### Combined Figure (Top and Bottom)

```{r}

ggsave(fig5_nc + (fig5_dem_rep /  fig5_dem_vs_rep) + 
         plot_annotation(tag_levels = 'A'), 
       width = 10, height = 6.5, 
       filename = here("figures", "main", "fig5.pdf"))


```


## Figure 5_a: Agreeable and Disagreeable Headlines, Separately, No Controls

### Top Row: Means

```{r}

fig5_nc_by_agreeableness <- 

  svyby(~share_01, ~hdl_true + ~party_dem + ~pooledTreat + ~hdl_agreeable, 
        FUN = svymean, 
        design = svydesign(~1, 
                           weights = ~weight, 
                           data = long %>% 
                             dplyr::select(share_01, hdl_true, hdl_agreeable, 
                                           party_dem, pooledTreat, 
                                           weight, caseid, hdl_id) %>%
                             na.omit())) %>%
  
  mutate(hdl_true = ifelse(hdl_true == 1, "True Headlines", "False Headlines")) %>%
  mutate(party_dem = ifelse(party_dem == 0, "Republicans", "Democrats")) %>%
  mutate(hdl_agreeable = ifelse(hdl_agreeable == 0, "Disagreeable Headlines", "Agreeable Headlines")) %>%
  
    ggplot(aes(x = factor(party_dem), 
               y = share_01, 
               ymin = share_01 - 1.96*se,
               ymax = share_01 + 1.96*se,
               label = round(share_01, 2),
               fill = factor(pooledTreat))) +
    geom_bar(stat = "identity", position = position_dodge()) +
    geom_errorbar(size = .3, width = .2, position = position_dodge(.9)) + 
    geom_text(aes(y = share_01 + 1.96*se), 
              position = position_dodge(.9), vjust = -1, size = 3) +  
    facet_grid(cols = vars(hdl_agreeable), rows = vars(hdl_true)) + 
    theme_minimal() + 
    xlab("Respondent Party") + 
    ylab("Mean Sharing Intention") + 
    ylim(c(0, .5)) + 
    scale_fill_manual(breaks = c(0, 1), 
                      labels = c("Control", "Treatment"), 
                      values = c("gray80", "gray40"), 
                      name = "") + 
    theme(legend.position = c(.8, .9))
  
```

### Bottom Row: Discernment

```{r}

fig5_dem_rep_by_agreeableness <- 
  
  rbind(
    
    # agreeable headlines
    summary(m9nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", hdl_agreeable = "Agreeable"),
    
    summary(m10nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", hdl_agreeable = "Agreeable"),
    
   # disagreeable headlines
    summary(m12nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", hdl_agreeable = "Disagreeable"),
    
    summary(m13nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", hdl_agreeable = "Disagreeable")) %>%
  
  ggplot(aes(x = respondent_party, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`, 
             shape = hdl_agreeable)) + 
  geom_hline(yintercept = 1) +
  geom_pointrange(position = position_dodge(.4)) + 
  scale_shape_manual(breaks = c("Agreeable", "Disagreeable"), 
                    values = c(16, 15), 
                    name = "Headline Type")   + 
  theme_bw() + 
  xlab("") + 
  ylim(c(.95, 1.4)) + 
  ylab("Treattment Effect on Discernment")


# Dem vs. Rep Difference
fig5_dem_vs_rep_by_agreeableness <- 
rbind(
  
  # agreeable
  summary(m8nc_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", hdl_agreeable = "Agreeable"), 
  
  # disagreeable
  summary(m11nc_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", hdl_agreeable = "Disagreeable")) %>%
  
  mutate(quantity = ifelse(quantity == "ratioleft_div_ratioright", "Treatment Effect on Discernment: Democrat / Republican", NA)) %>%
  
  ggplot(aes(x = quantity, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`, 
             shape = hdl_agreeable)) + 
  geom_hline(yintercept = 1) + 
  geom_pointrange(position = position_dodge(.4)) +
  theme(legend.position = "none") + 
  scale_shape_manual(breaks = c("Agreeable", "Disagreeable"), 
                     values = c(16, 15), 
                     name = "Headline Type")   +
  theme_bw() + 
  xlab("") + 
  ylab("Treatment Effect on Discernment \n(Democrat / Republican)") + 
  ylim(c(.80, 1.27)) + 
  theme(legend.position = "none", axis.text.x = element_blank())

```


### Combined Figure (Top and Bottom)

```{r}

ggsave(
fig5_nc_by_agreeableness + (fig5_dem_rep_by_agreeableness /  fig5_dem_vs_rep_by_agreeableness) + plot_annotation(tag_levels = 'A') , 
width = 14, height = 6, filename = here("figures", "sm", "fig5_a.pdf"))

```


## Figure 5b: Agreeable + Disagreeable Headlines Together, With Controls

### Top Row: Means

### Bottom Row: Discernment

```{r}

fig5_b_dem_rep <- 
  
  rbind(
    
    summary(m6c_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans"),
    
    summary(m7c_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats")) %>%
    
  
  ggplot(aes(x = respondent_party, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 1) +
  geom_pointrange(position = position_dodge(.4)) + 
  # scale_color_manual(breaks = c("Democratic", "Republican"), 
  #                    values = c(cb_blue, cb_red))   + 
  theme_bw() + 
  xlab("") + 
  ylim(c(.8, 1.35)) + 
  ylab("Treattment Effect on Discernment")

# Dem vs. Rep Difference
fig5_b_dem_vs_rep <- 
  rbind(
    
    summary(m5c_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratioleft_div_ratioright") %>% 
      mutate(respondent_party = "All")) %>%
    
    mutate(quantity = ifelse(quantity == "ratioleft_div_ratioright", "Treatment Effect on Discernment: Democrat / Republican", NA)) %>%
  
  ggplot(aes(x = quantity, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 1) + 
  geom_pointrange(position = position_dodge(.4)) +
  theme(legend.position = "none") + 
  theme_bw() + 
  xlab("") + 
  ylab("Treatment Effect on Discernment \n(Democrat / Republican)") + 
  ylim(c(.8, 1.35)) + 
  theme(axis.text.x = element_blank())

```


### Combined Figure (Top and Bottom)

```{r}

ggsave(fig5_nc + (fig5_b_dem_rep /  fig5_b_dem_vs_rep) + 
         plot_annotation(tag_levels = 'A'), 
       width = 10, height = 6.5, 
       filename = here("figures", "sm", "fig5_b.pdf"))


```


## Figure 5c: Agreeable + Disagreeable Headlines Together, No Controls, Additive Discernment


## Figure 5: Agreeable + Disagreeable Headlines Together, No Controls


### Bottom Row: Discernment

```{r}

# Dem and Rep
fig5_c_dem_rep <- 
  
  rbind(
    
    summary(m6nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "diff_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans"),
    
    summary(m7nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "diff_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats")) %>%
    
  
  ggplot(aes(x = respondent_party, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 0) +
  geom_pointrange(position = position_dodge(.4)) + 
  # scale_color_manual(breaks = c("Democratic", "Republican"), 
  #                    values = c(cb_blue, cb_red))   + 
  theme_bw() + 
  xlab("") + 
  ylim(c(0, .07)) + 
  ylab("Treatment Effect on Discernment")


# Dem vs. Rep Difference
fig5_c_dem_vs_rep <- 
  rbind(
    
    summary(m5nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "diffleft_minus_diffright") %>% 
      mutate(respondent_party = "All")) %>%
    
    mutate(quantity = ifelse(quantity == "diffleft_minus_diffright", "Treatment Effect on Discernment: Democrat / Republican", NA)) %>%
  
  ggplot(aes(x = quantity, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`)) + 
  geom_hline(yintercept = 0) + 
  geom_pointrange(position = position_dodge(.4)) +
  theme(legend.position = "none") + 
  theme_bw() + 
  xlab("") + 
  ylab("Treatment Effect on Discernment \n(Democrat - Republican)") 

```


### Combined Figure (Top and Bottom)

```{r}

ggsave(fig5_nc + (fig5_c_dem_rep /  fig5_c_dem_vs_rep) + 
         plot_annotation(tag_levels = 'A'), 
       width = 10, height = 6.5, 
       filename = here("figures", "sm", "fig5_c.pdf"))

```


## Figure 6: Experimental Figure by Intervention Type

### Create Treatment Condition Conditions

```{r}

long$treat_accuracy <- ifelse(long$cond_int == "accuracy", 1, 
                              ifelse(long$cond_int == "control", 0, NA))

long$treat_headline <- ifelse(long$cond_int == "headline", 1, 
                              ifelse(long$cond_int == "control", 0, NA))

long$treat_headlineFeedback <- ifelse(long$cond_int == "headlineFeedback", 1, 
                              ifelse(long$cond_int == "control", 0, NA))

long$treat_psa <- ifelse(long$cond_int == "psa", 1, 
                              ifelse(long$cond_int == "control", 0, NA))

```

### 1) Pooled

#### All Respondents

```{r}

m5nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data)

m5nc_true <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data %>% filter(hdl_true == 1))

m5nc_false <-  
  glm(share_01 ~ pooledTreat*party_dem,
      family = "gaussian", weights = weight, data = m5nc_data %>% filter(hdl_true == 0))

m5nc_sim <- 
  clarify::sim(m5nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_all, g1 = m5nc_all$data$caseid, g2 = m5nc_all$data$hdl_id))

m5nc_sim_apply <- 
  sim_apply(m5nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 0, pooledTreat = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 1, party_dem = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 0, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_data %>% mutate(hdl_true = 0, party_dem = 1, pooledTreat = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_transformed <-
  transform(m5nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```

#### Republican Respondents

```{r}

m6nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data)

m6nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data %>% filter(hdl_true == 1))

m6nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m6nc_data %>% filter(hdl_true == 0))

m6nc_sim <- 
  clarify::sim(m6nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_all, g1 = m6nc_all$data$caseid, g2 = m6nc_all$data$hdl_id))

m6nc_sim_apply <- 
  sim_apply(m6nc_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_transformed <-
  transform(m6nc_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

#### Democratic Respondents

```{r}

m7nc_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, pooledTreat, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7nc_all <-  
  glm(share_01 ~ hdl_true*pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data)

m7nc_true <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data %>% filter(hdl_true == 1))

m7nc_false <-  
  glm(share_01 ~ pooledTreat,
      family = "gaussian", weights = weight, data = m7nc_data %>% filter(hdl_true == 0))

m7nc_sim <- 
  clarify::sim(m7nc_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_all, g1 = m7nc_all$data$caseid, g2 = m7nc_all$data$hdl_id))

m7nc_sim_apply <- 
  sim_apply(m7nc_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 1, pooledTreat = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 0, pooledTreat = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 1, pooledTreat = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_data %>% mutate(hdl_true = 0, pooledTreat = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_transformed <-
  transform(m7nc_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```


### 2) Accuracy

#### All Respondents

```{r}

m5nc_treat_accuracy_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_accuracy, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_treat_accuracy_all <-  
  glm(share_01 ~ hdl_true*treat_accuracy*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_accuracy_data)

m5nc_treat_accuracy_true <-  
  glm(share_01 ~ treat_accuracy*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_accuracy_data %>% filter(hdl_true == 1))

m5nc_treat_accuracy_false <-  
  glm(share_01 ~ treat_accuracy*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_accuracy_data %>% filter(hdl_true == 0))

m5nc_treat_accuracy_sim <- 
  clarify::sim(m5nc_treat_accuracy_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_treat_accuracy_all, g1 = m5nc_treat_accuracy_all$data$caseid, g2 = m5nc_treat_accuracy_all$data$hdl_id))

m5nc_treat_accuracy_sim_apply <- 
  sim_apply(m5nc_treat_accuracy_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 1, party_dem = 0, treat_accuracy = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 1, party_dem = 1, treat_accuracy = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 0, party_dem = 0, treat_accuracy = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 0, party_dem = 1, treat_accuracy = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 1, party_dem = 0, treat_accuracy = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 1, party_dem = 1, treat_accuracy = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 0, party_dem = 0, treat_accuracy = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_treat_accuracy_data %>% mutate(hdl_true = 0, party_dem = 1, treat_accuracy = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_treat_accuracy_transformed <-
  transform(m5nc_treat_accuracy_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```

#### Republican Respondents

```{r}

m6nc_treat_accuracy_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_accuracy, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_treat_accuracy_all <-  
  glm(share_01 ~ hdl_true*treat_accuracy,
      family = "gaussian", weights = weight, data = m6nc_treat_accuracy_data)

m6nc_treat_accuracy_true <-  
  glm(share_01 ~ treat_accuracy,
      family = "gaussian", weights = weight, data = m6nc_treat_accuracy_data %>% filter(hdl_true == 1))

m6nc_treat_accuracy_false <-  
  glm(share_01 ~ treat_accuracy,
      family = "gaussian", weights = weight, data = m6nc_treat_accuracy_data %>% filter(hdl_true == 0))

m6nc_treat_accuracy_sim <- 
  clarify::sim(m6nc_treat_accuracy_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_treat_accuracy_all, g1 = m6nc_treat_accuracy_all$data$caseid, g2 = m6nc_treat_accuracy_all$data$hdl_id))

m6nc_treat_accuracy_sim_apply <- 
  sim_apply(m6nc_treat_accuracy_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_treat_accuracy_data %>% mutate(hdl_true = 1, treat_accuracy = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_treat_accuracy_data %>% mutate(hdl_true = 0, treat_accuracy = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_treat_accuracy_data %>% mutate(hdl_true = 1, treat_accuracy = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_treat_accuracy_data %>% mutate(hdl_true = 0, treat_accuracy = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_treat_accuracy_transformed <-
  transform(m6nc_treat_accuracy_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

#### Democratic Respondents

```{r}

m7nc_treat_accuracy_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_accuracy, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7nc_treat_accuracy_all <-  
  glm(share_01 ~ hdl_true*treat_accuracy,
      family = "gaussian", weights = weight, data = m7nc_treat_accuracy_data)

m7nc_treat_accuracy_true <-  
  glm(share_01 ~ treat_accuracy,
      family = "gaussian", weights = weight, data = m7nc_treat_accuracy_data %>% filter(hdl_true == 1))

m7nc_treat_accuracy_false <-  
  glm(share_01 ~ treat_accuracy,
      family = "gaussian", weights = weight, data = m7nc_treat_accuracy_data %>% filter(hdl_true == 0))

m7nc_treat_accuracy_sim <- 
  clarify::sim(m7nc_treat_accuracy_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_treat_accuracy_all, g1 = m7nc_treat_accuracy_all$data$caseid, g2 = m7nc_treat_accuracy_all$data$hdl_id))

m7nc_treat_accuracy_sim_apply <- 
  sim_apply(m7nc_treat_accuracy_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_treat_accuracy_data %>% mutate(hdl_true = 1, treat_accuracy = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_treat_accuracy_data %>% mutate(hdl_true = 0, treat_accuracy = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_treat_accuracy_data %>% mutate(hdl_true = 1, treat_accuracy = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_treat_accuracy_data %>% mutate(hdl_true = 0, treat_accuracy = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_treat_accuracy_transformed <-
  transform(m7nc_treat_accuracy_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```

### 3) Headline

#### All Respondents

```{r}

m5nc_treat_headline_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headline, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_treat_headline_all <-  
  glm(share_01 ~ hdl_true*treat_headline*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headline_data)

m5nc_treat_headline_true <-  
  glm(share_01 ~ treat_headline*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headline_data %>% filter(hdl_true == 1))

m5nc_treat_headline_false <-  
  glm(share_01 ~ treat_headline*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headline_data %>% filter(hdl_true == 0))

m5nc_treat_headline_sim <- 
  clarify::sim(m5nc_treat_headline_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_treat_headline_all, g1 = m5nc_treat_headline_all$data$caseid, g2 = m5nc_treat_headline_all$data$hdl_id))

m5nc_treat_headline_sim_apply <- 
  sim_apply(m5nc_treat_headline_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 1, party_dem = 0, treat_headline = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 1, party_dem = 1, treat_headline = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 0, party_dem = 0, treat_headline = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 0, party_dem = 1, treat_headline = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 1, party_dem = 0, treat_headline = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 1, party_dem = 1, treat_headline = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 0, party_dem = 0, treat_headline = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_treat_headline_data %>% mutate(hdl_true = 0, party_dem = 1, treat_headline = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_treat_headline_transformed <-
  transform(m5nc_treat_headline_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```

#### Republican Respondents

```{r}

m6nc_treat_headline_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headline, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_treat_headline_all <-  
  glm(share_01 ~ hdl_true*treat_headline,
      family = "gaussian", weights = weight, data = m6nc_treat_headline_data)

m6nc_treat_headline_true <-  
  glm(share_01 ~ treat_headline,
      family = "gaussian", weights = weight, data = m6nc_treat_headline_data %>% filter(hdl_true == 1))

m6nc_treat_headline_false <-  
  glm(share_01 ~ treat_headline,
      family = "gaussian", weights = weight, data = m6nc_treat_headline_data %>% filter(hdl_true == 0))

m6nc_treat_headline_sim <- 
  clarify::sim(m6nc_treat_headline_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_treat_headline_all, g1 = m6nc_treat_headline_all$data$caseid, g2 = m6nc_treat_headline_all$data$hdl_id))

m6nc_treat_headline_sim_apply <- 
  sim_apply(m6nc_treat_headline_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_treat_headline_data %>% mutate(hdl_true = 1, treat_headline = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_treat_headline_data %>% mutate(hdl_true = 0, treat_headline = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_treat_headline_data %>% mutate(hdl_true = 1, treat_headline = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_treat_headline_data %>% mutate(hdl_true = 0, treat_headline = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_treat_headline_transformed <-
  transform(m6nc_treat_headline_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

#### Democratic Respondents

```{r}

m7nc_treat_headline_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headline, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7nc_treat_headline_all <-  
  glm(share_01 ~ hdl_true*treat_headline,
      family = "gaussian", weights = weight, data = m7nc_treat_headline_data)

m7nc_treat_headline_true <-  
  glm(share_01 ~ treat_headline,
      family = "gaussian", weights = weight, data = m7nc_treat_headline_data %>% filter(hdl_true == 1))

m7nc_treat_headline_false <-  
  glm(share_01 ~ treat_headline,
      family = "gaussian", weights = weight, data = m7nc_treat_headline_data %>% filter(hdl_true == 0))

m7nc_treat_headline_sim <- 
  clarify::sim(m7nc_treat_headline_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_treat_headline_all, g1 = m7nc_treat_headline_all$data$caseid, g2 = m7nc_treat_headline_all$data$hdl_id))

m7nc_treat_headline_sim_apply <- 
  sim_apply(m7nc_treat_headline_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_treat_headline_data %>% mutate(hdl_true = 1, treat_headline = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_treat_headline_data %>% mutate(hdl_true = 0, treat_headline = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_treat_headline_data %>% mutate(hdl_true = 1, treat_headline = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_treat_headline_data %>% mutate(hdl_true = 0, treat_headline = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_treat_headline_transformed <-
  transform(m7nc_treat_headline_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```


## 4) Headline w/ Feedback

#### All Respondents

```{r}

m5nc_treat_headlineFeedback_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headlineFeedback, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_treat_headlineFeedback_all <-  
  glm(share_01 ~ hdl_true*treat_headlineFeedback*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headlineFeedback_data)

m5nc_treat_headlineFeedback_true <-  
  glm(share_01 ~ treat_headlineFeedback*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headlineFeedback_data %>% filter(hdl_true == 1))

m5nc_treat_headlineFeedback_false <-  
  glm(share_01 ~ treat_headlineFeedback*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_headlineFeedback_data %>% filter(hdl_true == 0))

m5nc_treat_headlineFeedback_sim <- 
  clarify::sim(m5nc_treat_headlineFeedback_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_treat_headlineFeedback_all, g1 = m5nc_treat_headlineFeedback_all$data$caseid, g2 = m5nc_treat_headlineFeedback_all$data$hdl_id))

m5nc_treat_headlineFeedback_sim_apply <- 
  sim_apply(m5nc_treat_headlineFeedback_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, party_dem = 0, treat_headlineFeedback = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, party_dem = 1, treat_headlineFeedback = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, party_dem = 0, treat_headlineFeedback = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, party_dem = 1, treat_headlineFeedback = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, party_dem = 0, treat_headlineFeedback = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, party_dem = 1, treat_headlineFeedback = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, party_dem = 0, treat_headlineFeedback = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, party_dem = 1, treat_headlineFeedback = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_treat_headlineFeedback_transformed <-
  transform(m5nc_treat_headlineFeedback_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


#### Republican Respondents

```{r}

m6nc_treat_headlineFeedback_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headlineFeedback, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_treat_headlineFeedback_all <-  
  glm(share_01 ~ hdl_true*treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m6nc_treat_headlineFeedback_data)

m6nc_treat_headlineFeedback_true <-  
  glm(share_01 ~ treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m6nc_treat_headlineFeedback_data %>% filter(hdl_true == 1))

m6nc_treat_headlineFeedback_false <-  
  glm(share_01 ~ treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m6nc_treat_headlineFeedback_data %>% filter(hdl_true == 0))

m6nc_treat_headlineFeedback_sim <- 
  clarify::sim(m6nc_treat_headlineFeedback_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_treat_headlineFeedback_all, g1 = m6nc_treat_headlineFeedback_all$data$caseid, g2 = m6nc_treat_headlineFeedback_all$data$hdl_id))

m6nc_treat_headlineFeedback_sim_apply <- 
  sim_apply(m6nc_treat_headlineFeedback_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, treat_headlineFeedback = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, treat_headlineFeedback = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, treat_headlineFeedback = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, treat_headlineFeedback = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_treat_headlineFeedback_transformed <-
  transform(m6nc_treat_headlineFeedback_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

#### Democratic Respondents

```{r}

m7nc_treat_headlineFeedback_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_headlineFeedback, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7nc_treat_headlineFeedback_all <-  
  glm(share_01 ~ hdl_true*treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m7nc_treat_headlineFeedback_data)

m7nc_treat_headlineFeedback_true <-  
  glm(share_01 ~ treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m7nc_treat_headlineFeedback_data %>% filter(hdl_true == 1))

m7nc_treat_headlineFeedback_false <-  
  glm(share_01 ~ treat_headlineFeedback,
      family = "gaussian", weights = weight, data = m7nc_treat_headlineFeedback_data %>% filter(hdl_true == 0))

m7nc_treat_headlineFeedback_sim <- 
  clarify::sim(m7nc_treat_headlineFeedback_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_treat_headlineFeedback_all, g1 = m7nc_treat_headlineFeedback_all$data$caseid, g2 = m7nc_treat_headlineFeedback_all$data$hdl_id))

m7nc_treat_headlineFeedback_sim_apply <- 
  sim_apply(m7nc_treat_headlineFeedback_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, treat_headlineFeedback = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, treat_headlineFeedback = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_treat_headlineFeedback_data %>% mutate(hdl_true = 1, treat_headlineFeedback = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_treat_headlineFeedback_data %>% mutate(hdl_true = 0, treat_headlineFeedback = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_treat_headlineFeedback_transformed <-
  transform(m7nc_treat_headlineFeedback_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```



### 5) PSA

#### All Respondents

```{r}

m5nc_treat_psa_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_psa, weight, caseid, hdl_id) %>%
  na.omit()

m5nc_treat_psa_all <-  
  glm(share_01 ~ hdl_true*treat_psa*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_psa_data)

m5nc_treat_psa_true <-  
  glm(share_01 ~ treat_psa*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_psa_data %>% filter(hdl_true == 1))

m5nc_treat_psa_false <-  
  glm(share_01 ~ treat_psa*party_dem,
      family = "gaussian", weights = weight, data = m5nc_treat_psa_data %>% filter(hdl_true == 0))

m5nc_treat_psa_sim <- 
  clarify::sim(m5nc_treat_psa_all, n = n_sim, vcov = xeffect.glm(glm.obj = m5nc_treat_psa_all, g1 = m5nc_treat_psa_all$data$caseid, g2 = m5nc_treat_psa_all$data$hdl_id))

m5nc_treat_psa_sim_apply <- 
  sim_apply(m5nc_treat_psa_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 1, party_dem = 0, treat_psa = 1), type = "response")
              true_left_treat <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 1, party_dem = 1, treat_psa = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 0, party_dem = 0, treat_psa = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 0, party_dem = 1, treat_psa = 1), type = "response")
              
              true_right_control <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 1, party_dem = 0, treat_psa = 0), type = "response")
              true_left_control <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 1, party_dem = 1, treat_psa = 0), type = "response")
              false_right_control <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 0, party_dem = 0, treat_psa = 0), type = "response")
              false_left_control <- predict(fit, newdata = m5nc_treat_psa_data %>% mutate(hdl_true = 0, party_dem = 1, treat_psa = 0), type = "response")
              
              c(true_right_treat = mean(true_right_treat), true_left_treat = mean(true_left_treat), 
                false_right_treat = mean(false_right_treat), false_left_treat = mean(false_left_treat), 
                true_right_control = mean(true_right_control), true_left_control = mean(true_left_control), 
                false_right_control = mean(false_right_control), false_left_control = mean(false_left_control))})

m5nc_treat_psa_transformed <-
  transform(m5nc_treat_psa_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat, 
            
            
            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
            # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`, 
            `diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`) %>%

            # right minus left
  transform(`diffleft_minus_diffright` = `diff_treatmenteffect_left` - `diff_treatmenteffect_right`,
            `ratioleft_div_ratioright` = `ratio_treatmenteffect_left` / `ratio_treatmenteffect_right`,
            `ratioleft_minus_ratioright` = `ratio_treatmenteffect_left` - `ratio_treatmenteffect_right`)

```


#### Republican Respondents

```{r}

m6nc_treat_psa_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_psa, weight, caseid, hdl_id) %>%
  filter(party_dem == 0) %>%
  na.omit()

m6nc_treat_psa_all <-  
  glm(share_01 ~ hdl_true*treat_psa,
      family = "gaussian", weights = weight, data = m6nc_treat_psa_data)

m6nc_treat_psa_true <-  
  glm(share_01 ~ treat_psa,
      family = "gaussian", weights = weight, data = m6nc_treat_psa_data %>% filter(hdl_true == 1))

m6nc_treat_psa_false <-  
  glm(share_01 ~ treat_psa,
      family = "gaussian", weights = weight, data = m6nc_treat_psa_data %>% filter(hdl_true == 0))

m6nc_treat_psa_sim <- 
  clarify::sim(m6nc_treat_psa_all, n = n_sim, vcov = xeffect.glm(glm.obj = m6nc_treat_psa_all, g1 = m6nc_treat_psa_all$data$caseid, g2 = m6nc_treat_psa_all$data$hdl_id))

m6nc_treat_psa_sim_apply <- 
  sim_apply(m6nc_treat_psa_sim, cl = 6,
            function(fit){
              true_right_treat <- predict(fit, newdata = m6nc_treat_psa_data %>% mutate(hdl_true = 1, treat_psa = 1), type = "response")
              false_right_treat <- predict(fit, newdata = m6nc_treat_psa_data %>% mutate(hdl_true = 0, treat_psa = 1), type = "response")

              true_right_control <- predict(fit, newdata = m6nc_treat_psa_data %>% mutate(hdl_true = 1, treat_psa = 0), type = "response")
              false_right_control <- predict(fit, newdata = m6nc_treat_psa_data %>% mutate(hdl_true = 0, treat_psa = 0), type = "response")

              c(true_right_treat = mean(true_right_treat), 
                false_right_treat = mean(false_right_treat),
                true_right_control = mean(true_right_control),
                false_right_control = mean(false_right_control))})

m6nc_treat_psa_transformed <-
  transform(m6nc_treat_psa_sim_apply, 
            # true minus false
            `true_right_treat - false_right_treat` = true_right_treat - false_right_treat,
            `true_right_treat / false_right_treat` = true_right_treat / false_right_treat,

            `true_right_control - false_right_control` = true_right_control - false_right_control,
            `true_right_control / false_right_control` = true_right_control / false_right_control) %>%

  # treat minus control
  transform(`diff_treatmenteffect_right` = `true_right_treat - false_right_treat` - `true_right_control - false_right_control`, 
            `ratio_treatmenteffect_right` = `true_right_treat / false_right_treat` / `true_right_control / false_right_control`)

```

#### Democratic Respondents

```{r}

m7nc_treat_psa_data <- 
  long %>% 
  dplyr::select(share_01, hdl_true, party_dem, treat_psa, weight, caseid, hdl_id) %>%
  filter(party_dem == 1) %>%
  na.omit()


m7nc_treat_psa_all <-  
  glm(share_01 ~ hdl_true*treat_psa,
      family = "gaussian", weights = weight, data = m7nc_treat_psa_data)

m7nc_treat_psa_true <-  
  glm(share_01 ~ treat_psa,
      family = "gaussian", weights = weight, data = m7nc_treat_psa_data %>% filter(hdl_true == 1))

m7nc_treat_psa_false <-  
  glm(share_01 ~ treat_psa,
      family = "gaussian", weights = weight, data = m7nc_treat_psa_data %>% filter(hdl_true == 0))

m7nc_treat_psa_sim <- 
  clarify::sim(m7nc_treat_psa_all, n = n_sim, vcov = xeffect.glm(glm.obj = m7nc_treat_psa_all, g1 = m7nc_treat_psa_all$data$caseid, g2 = m7nc_treat_psa_all$data$hdl_id))

m7nc_treat_psa_sim_apply <- 
  sim_apply(m7nc_treat_psa_sim, cl = 6,
            function(fit){
              true_left_treat <- predict(fit, newdata = m7nc_treat_psa_data %>% mutate(hdl_true = 1, treat_psa = 1), type = "response")
              false_left_treat <- predict(fit, newdata = m7nc_treat_psa_data %>% mutate(hdl_true = 0, treat_psa = 1), type = "response")
              
              true_left_control <- predict(fit, newdata = m7nc_treat_psa_data %>% mutate(hdl_true = 1, treat_psa = 0), type = "response")
              false_left_control <- predict(fit, newdata = m7nc_treat_psa_data %>% mutate(hdl_true = 0, treat_psa = 0), type = "response")
              
              c(true_left_treat = mean(true_left_treat), 
                false_left_treat = mean(false_left_treat),
                true_left_control = mean(true_left_control),
                false_left_control = mean(false_left_control))})

m7nc_treat_psa_transformed <-
  transform(m7nc_treat_psa_sim_apply, 
            # true minus false
            `true_left_treat - false_left_treat` = true_left_treat - false_left_treat,
            `true_left_treat / false_left_treat` = true_left_treat / false_left_treat,
            
            `true_left_control - false_left_control` = true_left_control - false_left_control,
            `true_left_control / false_left_control` = true_left_control / false_left_control) %>%
  
  # treat minus control
  transform(`diff_treatmenteffect_left` = `true_left_treat - false_left_treat` - `true_left_control - false_left_control`, 
            `ratio_treatmenteffect_left` = `true_left_treat / false_left_treat` / `true_left_control / false_left_control`)

```

### Save Figure 6

```{r}

# Dem and Rep

fig5_dem_rep_byinterventiontype <- 
  
  rbind(
    
    # pooled 
    summary(m6nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", intervention = "Pooled"),
    
    summary(m7nc_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", intervention = "Pooled"),
    
    # accuracy
    summary(m6nc_treat_accuracy_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", intervention = "Accuracy"),
    
    summary(m7nc_treat_accuracy_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", intervention = "Accuracy"),
    
    # headline
    summary(m6nc_treat_headline_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", intervention = "Headline"),
    
    summary(m7nc_treat_headline_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", intervention = "Headline"),
    
    # headline w/ feedback
    summary(m6nc_treat_headlineFeedback_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", intervention = "Headline w/ Feedback"),
    
    summary(m7nc_treat_headlineFeedback_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", intervention = "Headline w/ Feedback"),
    
    # psa
    summary(m6nc_treat_psa_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_right") %>% 
      mutate(respondent_party = "Republicans", intervention = "PSA"),
    
    summary(m7nc_treat_psa_transformed) %>%
      as.data.frame() %>%
      rownames_to_column("quantity") %>%
      filter(quantity == "ratio_treatmenteffect_left") %>% 
      mutate(respondent_party = "Democrats", intervention = "PSA")) %>%
  
    mutate(intervention = factor(intervention, levels = c("Pooled", "Accuracy", "Headline", "Headline w/ Feedback", "PSA"))) %>%
  
  ggplot(aes(x = respondent_party, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`, 
             shape = intervention)) + 
  geom_hline(yintercept = 1) +
  geom_pointrange(position = position_dodge(.4)) + 
  # scale_color_manual(breaks = c("Democratic", "Republican"), 
  #                    values = c(cb_blue, cb_red))   + 
  theme_bw() + 
  theme(legend.position = "bottom") +
  xlab("") + 
  ylim(c(.6, 1.65)) + 
  ylab("Treattment Effect on Discernment") + 
  scale_shape_manual(breaks = c("Pooled", "Accuracy", "Headline", "Headline w/ Feedback", "PSA"),
                     values = c(15, 1, 0, 2, 5),
                     name = "Intervention Type:")


# Dem vs. Rep Difference
fig5_dem_vs_rep_byinterventiontype <- 
rbind(
  
  # pooled
  summary(m5nc_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", intervention = "Pooled"), 
  
  # accuracy
  summary(m5nc_treat_accuracy_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", intervention = "Importance + Norms"),
  
  # headline
  summary(m5nc_treat_headline_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", intervention = "Evaluation"),
  
  # headline w/ feedback
  summary(m5nc_treat_headlineFeedback_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", intervention = "Evaluation w/ Feedback"),
  
  # psa
  summary(m5nc_treat_psa_transformed) %>%
    as.data.frame() %>%
    rownames_to_column("quantity") %>%
    filter(quantity == "ratioleft_div_ratioright") %>% 
    mutate(respondent_party = "All", intervention = "PSA")) %>%
  
  mutate(quantity = ifelse(quantity == "ratioleft_div_ratioright", "Treatment Effect on Discernment: Democrat / Republican", NA)) %>%
  
  mutate(intervention = factor(intervention, levels = c("Pooled", "Importance + Norms", "Evaluation", "Evaluation w/ Feedback", "PSA"))) %>%
  
  ggplot(aes(x = quantity, 
             y = Estimate, 
             ymin = `2.5 %`, 
             ymax = `97.5 %`, 
             shape = intervention)) + 
  geom_hline(yintercept = 1) + 
  geom_pointrange(position = position_dodge(.4)) +
  theme_bw() + 
  theme(legend.position = "bottom") + 
  xlab("") + 
  ylim(c(.6, 1.65)) + 
  scale_shape_manual(breaks = c("Pooled", "Importance + Norms", "Evaluation", "Evaluation w/ Feedback", "PSA"),
                     values = c(15, 1, 0, 2, 5),
                     name = "Intervention Type:") 
  
ggsave(
fig5_dem_rep_byinterventiontype +  fig5_dem_vs_rep_byinterventiontype + plot_annotation(tag_levels = 'A') +  plot_layout(guides = "collect") & theme(legend.position = "bottom") , 
width = 9, height = 4, filename = here("figures", "main", "fig6.pdf"))

```


# Collapsed Models for Appendix

```{r, eval = F}

short_mean <- 
long %>%
  filter(party != "ind") %>%
  group_by(caseid) %>%
  summarize(share_true_all_mean = mean(share_01[hdl_true == 1]), 
            share_false_all_mean = mean(share_01[hdl_true == 0]), 
            share_true_agreeable_mean = mean(share_01[hdl_true == 1 & hdl_agreeable == 1]), 
            share_false_agreeable_mean = mean(share_01[hdl_true == 0 & hdl_agreeable == 1]), 
            share_true_disagreeable_mean = mean(share_01[hdl_true == 1 & hdl_agreeable == 0]), 
            share_false_disagreeable_mean = mean(share_01[hdl_true == 0 & hdl_agreeable == 0])) %>%
  mutate(true_minus_false_all = share_true_all_mean - share_false_all_mean, 
         true_div_false_all = share_true_all_mean / share_false_all_mean, 
         true_minus_false_agreeable = share_true_agreeable_mean - share_false_agreeable_mean, 
         true_div_false_agreeable = share_true_agreeable_mean / share_false_agreeable_mean, 
         true_minus_false_disagreeable = share_true_disagreeable_mean - share_false_disagreeable_mean, 
         true_div_false_disagreeable = share_true_disagreeable_mean / share_false_disagreeable_mean)

short_mean[short_mean == Inf] <- NA

# Number of excluded respondents (for all headlines..not broken out by agreeableness)
round(prop.table(table(short_mean$share_true_mean == 0)),2)
round(prop.table(table(short_mean$share_false_mean == 0)),2)
round(prop.table(table(short_mean$share_true_mean == 0 & short_mean$share_false_mean == 0)),2)

short <- merge(yougov %>% 
                mutate(caseid = id) %>% 
                filter(party != "ind") %>%
                filter(covpol_split == 1),
              short_mean, by = "caseid")

# basic models (agreeable headlines): 
summary(lm(true_minus_false_agreeable ~ party_dem + female + education_sd + age_sd, data = short %>% filter(cond_int == "control")))
summary(lm(true_div_false_agreeable ~ party_dem + female + education_sd + age_sd, data = short %>% filter(cond_int == "control")))

# basic models (disagreeable headlines): 
summary(lm(true_minus_false_disagreeable ~ party_dem + female + education_sd + age_sd, data = short %>% filter(cond_int == "control")))
summary(lm(true_div_false_disagreeable ~ party_dem + female + education_sd + age_sd, data = short %>% filter(cond_int == "control")))

# basic experimental models (all headlines):
summary(lm(true_minus_false_all ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))
summary(lm(true_div_false_all ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))

# basic experimental models (agreeable headlines):
summary(lm(true_minus_false_agreeable ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))
summary(lm(true_div_false_agreeable ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))

# basic experimental models (disagreeable headlines):
summary(lm(true_minus_false_disagreeable ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))
summary(lm(true_div_false_disagreeable ~ pooledTreat*party_dem + female + education_sd + age_sd, data = short))

```


# P Values for Main Text

```{r}

# Figure 5 p values 
summary(m6nc_transformed, parm = "ratio_treatmenteffect_right", null = 1)
summary(m7nc_transformed, parm = "ratio_treatmenteffect_left", null = 1)
summary(m5nc_transformed, parm = "ratio_treatmenteffect_left", null = 1)
summary(m5nc_transformed, parm = "ratioleft_div_ratioright", null = 1)

```
